<?php
/**
 * 权限管理
 */
namespace app\module\admin\controller;

use app\BaseController;
use app\module\admin\common\MenuHelper;

class Auth extends BaseController
{
    /**
     * 获取用户菜单权限
     * @return \think\Response
     */
    public function getMenusList()
    {
        //获取权限控制
        $menus = config('menus');
        $loginUser = $this->getUserInfo();
        $authList = MenuHelper::getAuthList($loginUser['uid']);
        // 根据权限过滤菜单
        $filteredMenus = MenuHelper::filterMenusByAuth($menus, $authList);

        return $this->success([
            'menu_list' => $filteredMenus,
        ]);
    }

    /**
     * 获取用户全部权限
     * @return \think\Response
     */
    public function getAuth(){
        $loginUser = $this->getUserInfo();
        $authList = MenuHelper::getAuthList($loginUser['uid']);
        return $this->success([
            'auth_list' => $authList,
        ]);
    }
}
